package com.mskj.zxmy.controller;

import cn.dev33.satoken.stp.StpUtil;
import com.mskj.zxmy.common.Result;
import com.mskj.zxmy.dto.SignDTO;
import com.mskj.zxmy.service.AttendanceService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("")
@Tag(name = "签到")
public class AttendanceController {

    @Autowired
    private AttendanceService attendanceService;


    // 签到接口
    @PostMapping("/signIn")
    @Operation(summary = "签到")
    public Result<?> signIn(@RequestBody SignDTO dto) {
        dto.setSignIn(StpUtil.getLoginId().toString());
        attendanceService.signIn(dto);
        return Result.success("签到成功");
    }

    // 签出接口
    @PostMapping("/signOut")
    @Operation(summary = "签出")
    public Result<?> signOut(@RequestBody SignDTO dto) {
        // dto.setSignIn(当前登录人);
        attendanceService.signOut(dto);
        return Result.success("签出成功");
    }

    @GetMapping("/getProcessName")
    @Operation(summary = "扫码得到工序名称")
    public Result<String> getProcessNameByProcessId(@RequestParam Integer processId) {
        String processName = attendanceService.getProcessNameByProcessId(processId);
        return Result.success(processName);
    }
}